<?php echo $header; ?>
<div class="container wrap">
<div class="alert-wrap">
	<div class="alert-username alert-position">
		<?php if ($error_username) { ?>
		<div class="alert alert-warning text-center">
			<button type="button" class="close" data-dismiss="alert">
				<span aria-hidden="true">&times;</span>
				<span class="sr-only">Close</span>
			</button>
			<?php $error_username ?>
		</div>
		<?php } ?>
	</div>
	<div class="alert-email alert-position"></div>
	<div class="alert-password alert-position"></div>
	<div class="alert-repassword alert-position"></div>
	<div class="alert-reemail alert-position"></div>
</div>
<div class="row">
	<div class="col-lg-4 col-lg-offset-4 col-md-6 col-md-offset-3 col-sm-6 col-sm-offset-3 col-xs-6 col-xs-offset-3 register-body b-s-b">
		<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form-register">
			<div class="form-group has-feedback input-margin">
				<span class="glyphicon glyphicon-user form-control-feedback icon-pos-font"></span>
				<input type="text" name="username" id="register-username" class="input-bg form-control b-s-b" placeholder="用户名">
			</div>
			<div class="form-group has-feedback input-margin">
				<span class="glyphicon glyphicon-envelope form-control-feedback icon-pos-font"></span>
				<input type="text" name="email" id="register-email" class="input-bg form-control b-s-b" placeholder="邮箱地址">
			</div>
			<div class="form-group has-feedback input-margin input-margin-more">
				<span class="glyphicon glyphicon-lock form-control-feedback icon-pos-font"></span>
				<input type="password" name="password" id="register-password" class="form-control b-s-b input-bg" placeholder="密码">
				<span class="glyphicon glyphicon-eye-open form-control-feedback icon-font eye-password-display"></span>
			</div>
			<div class="form-group has-feedback input-margin input-margin-more">
				<span class="glyphicon glyphicon-lock form-control-feedback icon-pos-font"></span>
				<input type="password" name="repassword" id="re-register-password" class="form-control b-s-b input-bg" placeholder="再次输入密码">
				<span class="glyphicon glyphicon-eye-open form-control-feedback icon-font eye-password-display"></span>
			</div>
			<div class="input-margin input-margin-more">
				<a class="btn btn-primary btn-padding b-s-b" id="register-btn" href="javascript:void(0);">注册</a>
				<!-- <a class="btn btn-primary btn-padding b-s-b btn-margin-left" href="javascript:void(0);">重填</a> -->
				<input type="reset" value="重置" class="btn btn-primary btn-padding b-s-b btn-margin-left" id="register-reset">
			</div>
			<div class="input-margin-more">
				<p class="text-center">
					<a id="resendemail" href="javascript:void(0);">重发验证邮件</a>
				</p>
				<p class="text-center">
					<a href="<?php echo $loginurl; ?>">前往登陆</a>
				</p>
			</div>
		</form>
	</div>
</div>
</div>
<?php echo $footerout;?>
<script type="text/javascript">
$(document).ready(function(){
	$("#register-btn").on("click",function(){
		$(".alert-username,.alert-email,.alert-password,.alert-repassword,.alert-reemail").html();
		if(!register_vel()){
			return false;
		};
		var forminfo=$("#form-register").serialize();
		$.ajax({
			type:"POST",
			dataType:"json",
			url:"<?php echo $registervel; ?>",
			data:forminfo,
			success: function (data){
				var backalert = '<div class="alert alert-warning text-center"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
				var backinfo;
				if (data.username){
					backinfo =backalert+data.username+'</div>';
					$(".alert-username").html(backinfo);
					return;
				}
				if(data.email){
					backinfo =backalert+data.email+'</div>';
					$(".alert-email").html(backinfo);
					return;
				}
				$.ajax({
					type:"POST",
					dataType:"json",
					url:"<?php echo $action; ?>",
					data:forminfo,
					success: function (data){
						if(data.length == 0){
							alert("激活邮件已发送，请先前往您的邮箱激活账号！");
							window.location.href = "<?php echo $loginurl; ?>";
						}else{
							$(data).each(function(index,e){
								backinfo ="<div class='alert-registerfaild alert-position'>"+backalert+e+'</div></div>';
								$('.alert-repassword').after.backinfo;
							})
							
						}
						
					}
				});
			}
		})
	})
	$("#resendemail").on("click",function(){
		if(!register_vel()){
			return false;
		};
		var forminfo=$("#form-register").serialize();
		$.ajax({
			type:"POST",
			dataType:"json",
			url:"<?php echo $resendemail; ?>",
			data:forminfo,
			success: function (data){

				 var backalert = '<div class="alert alert-warning text-center"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
				 var backinfo;
				if(data === 1){
					backinfo =backalert+'邮件发送成功！</div>';
					$(".alert-reemail").html(backinfo);
					window.location.href = "<?php echo $loginurl; ?>";

				}else if(data === 2){
					backinfo =backalert+'邮箱尚未注册！</div>';
					$(".alert-reemail").html(backinfo);
				}else if(data === 3){
					backinfo =backalert+'请勿重复激活！</div>';
					$(".alert-reemail").html(backinfo);
				}else{
					backinfo =backalert+data+'</div>';
					$(".alert-reemail").html(backinfo);
				}
			}
		});
	});
})
</script>
<?php echo $footer; ?>